package com.api.controller;


import com.api.common.page.PageData;
import com.api.common.utils.Result;
import com.api.entity.Area;
import com.api.entity.dto.ItemDTO;
import com.api.service.AreaService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 地区码表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-13
 */

@Tag(name = "城市数据")
@RestController
@RequestMapping("/api/area")
@AllArgsConstructor
public class TbAreaController {


    private  final AreaService areaService;


    @GetMapping("province")
    @Operation(summary = "省份列表")
    public Result< List<String>> provinceList(){

        List<String> res = new ArrayList<>();
        LambdaQueryWrapper<Area> lwq = new LambdaQueryWrapper<>();
        lwq.eq(Area::getLevel ,1);
        List<Area> list = areaService.list(lwq);
        for (Area area : list) {
           String name = area.getAreaName()
                    .replace("市","")
                    .replace("自治区","")
                    .replace("省","");
           res.add(name);
        }
        return new Result< List<String>>().ok(res);
    }
}
